//
//  MassgeTheFont.m
//  YZZX
//
//  Created by Easaa on 15/4/27.
//  Copyright (c) 2015年 Easaa. All rights reserved.
//

#import "MassgeTheFont.h"

@implementation MassgeTheFont
{
    UIView      *bgView;
    NSInteger  _FontSizeNuber;   //选择字体大小
 

}



-(id)initWithViewFont:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
         //选择字体大小
        _FontSizeNuber =100;

    
        self.backgroundColor =RGBACOLOR(0, 0, 0, 0.2);
        [self addTarget:self action:@selector(Butfantion:) forControlEvents:UIControlEventTouchUpInside];
        
        bgView =[[UIView alloc]initWithFrame:CGRectMake((Dev_ScreenWidth-260)/2, (Dev_ScreenHeight-260)/2, 260, 240)];
        [bgView.layer setMasksToBounds:YES];
        [bgView.layer setCornerRadius:8]; //设置矩圆角半径
        [bgView.layer setBorderWidth:0];   //边框宽度
        bgView.backgroundColor =[UIColor whiteColor];
        [self addSubview:bgView];
        
        
        
        UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 260, 40)];
        labelTitle.font = [UIFont boldSystemFontOfSize:16.0];  //UILabel的字体大小
        labelTitle.numberOfLines = 0;  //必须定义这个属性，否则UILabel不会换行
        labelTitle.textColor = RGBCOLOR(252, 117, 148);
        labelTitle.textAlignment = NSTextAlignmentCenter;  //文本对齐方式
        //[labelTitle setBackgroundColor:[UIColor redColor]];
        labelTitle.text =@"选择字体";
        [bgView addSubview:labelTitle];
        
        
        UIView *Lineview =[[UIView alloc]initWithFrame:CGRectMake(0, 40, 260, 2)];
        Lineview.backgroundColor = RGBCOLOR(252, 117, 148);
        [bgView addSubview:Lineview];

        
        UIControl  *xiaoMassge = [self creatButtext:@"小号字"];
        xiaoMassge.frame = CGRectMake(0, 40, 260, 40);
        xiaoMassge.tag = 0;
        [xiaoMassge addTarget:self action:@selector(MassgeFantion:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:xiaoMassge];
        
        UIControl  *zhongMassge = [self creatButtext:@"中号字"];
        zhongMassge.frame = CGRectMake(0, 80, 260, 40);
        zhongMassge.tag = 1;
        [zhongMassge addTarget:self action:@selector(MassgeFantion:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:zhongMassge];

        
        UIControl  *daMassge = [self creatButtext:@"大号字"];
        daMassge.frame = CGRectMake(0, 120, 260, 40);
        daMassge.tag = 2;
        [daMassge addTarget:self action:@selector(MassgeFantion:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:daMassge];

        
        UIControl  *tedaMassge = [self creatButtext:@"特大号字"];
        tedaMassge.frame = CGRectMake(0, 160, 260, 40);
        tedaMassge.tag = 3;
        [tedaMassge addTarget:self action:@selector(MassgeFantion:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:tedaMassge];

        
        
        
        //拿到设置字体大小设置   ---初始化设置默认哪个大小
        NSUserDefaults *UserDefaultSize =[NSUserDefaults standardUserDefaults];
        float  _NuberSize = [UserDefaultSize floatForKey:YZZX_Font_Size];
        
        UIControl  *nubercontorl;
        if(_NuberSize == 13)
        {
            nubercontorl = xiaoMassge;
            _FontSizeNuber=13;
        }else if (_NuberSize == 16)
        {
            nubercontorl = zhongMassge;
            _FontSizeNuber=16;
        }else if (_NuberSize == 19)
        {
            nubercontorl = daMassge;
             _FontSizeNuber=19;
        
        }else if (_NuberSize == 22)
        {
            nubercontorl = tedaMassge;
             _FontSizeNuber=22;
        }
        
        if(nubercontorl != nil)
        {
            for (UIImageView  *iamgeview in [nubercontorl subviews])
            {
                if (iamgeview.tag ==20150505)
                {
                    iamgeview.highlighted = YES;
                }
            }
        }
        
        
        
        
        
        
        
    
        UIButton *BottomCancel = [UIButton buttonWithType:UIButtonTypeCustom];
        BottomCancel.tag = 0 ;
        BottomCancel.frame = CGRectMake(0,200, 260/2, 40);
        [BottomCancel addTarget:self action:@selector(settingButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [BottomCancel setTitle:@"取消" forState:UIControlStateNormal];
        [BottomCancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [BottomCancel setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        
        [bgView addSubview:BottomCancel];
        
        [BottomCancel.layer setMasksToBounds:YES];
        //[BottomCancel.layer setCornerRadius:5]; //设置矩圆角半径
        [BottomCancel.layer setBorderWidth:0];   //边框宽度
       
        

        UIButton *BottomConfirm = [UIButton buttonWithType:UIButtonTypeCustom];
        BottomConfirm.tag = 1 ;
        BottomConfirm.frame = CGRectMake(260/2,200, 260/2, 40);
        [BottomConfirm addTarget:self action:@selector(settingButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [BottomConfirm setTitle:@"确定" forState:UIControlStateNormal];
        [BottomConfirm setTitleColor:RGBCOLOR(252, 117, 148) forState:UIControlStateNormal];
        [BottomConfirm setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        [bgView addSubview:BottomConfirm];
        
        [BottomConfirm.layer setMasksToBounds:YES];
        //[BottomConfirm.layer setCornerRadius:5]; //设置矩圆角半径
        [BottomConfirm.layer setBorderWidth:0];   //边框宽度
    

        
        UIView *Lineviewbutton =[[UIView alloc]initWithFrame:CGRectMake(260/2,200, 1, 40)];
        Lineviewbutton.backgroundColor = RGBCOLOR(240, 240, 240);
        [bgView addSubview:Lineviewbutton];
        
        
     }
    
    return self;
    
}
-(UIControl *)creatButtext:(NSString *)textmassge
{
    UIControl *controlviewsetting  =[[UIControl alloc]init];
    //controlviewsetting.backgroundColor =[UIColor redColor];
    
    UIImageView * imagviewyz =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"btn_check_off_holo_light.png"] highlightedImage:[UIImage imageNamed:@"btn_check_on_holo_light.png"]];
    imagviewyz.frame = CGRectMake(10, 0, 40, 40);
    [controlviewsetting addSubview:imagviewyz];
    imagviewyz.tag = 20150505;
    
    
    UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 260-40, 40)];
    labelTitle.font = [UIFont boldSystemFontOfSize:14.0];  //UILabel的字体大小
    labelTitle.numberOfLines = 0;  //必须定义这个属性，否则UILabel不会换行
    labelTitle.textColor =[UIColor blackColor];
    labelTitle.textAlignment = NSTextAlignmentLeft;  //文本对齐方式
    //[labelTitle setBackgroundColor:[UIColor redColor]];
    labelTitle.text =textmassge;
    [controlviewsetting addSubview:labelTitle];
    
    UIView *LineviewCell =[[UIView alloc]initWithFrame:CGRectMake(0, 40, 260, 0.5)];
    LineviewCell.backgroundColor = RGBCOLOR(240, 240, 240);
    [controlviewsetting addSubview:LineviewCell];

    return controlviewsetting;
}



-(void)Butfantion:(UIControl *)control
{
    [self removeFromSuperview];
}


-(void)settingButtonClicked:(UIButton *)but
{
    //取消  确定
    if(but.tag == 0)
    {
        // 销毁
        [self removeFromSuperview];
    
    }else if (but.tag == 1)
    {
        //设置文章字体大小
        NSUserDefaults *UserDefaultSize =[NSUserDefaults standardUserDefaults];
        [UserDefaultSize setFloat:_FontSizeNuber forKey:YZZX_Font_Size];
        
        //回调  销毁
        [self.SizeDelegat  sizeFontNumber];
        [self removeFromSuperview];
    }
    
}

-(void)MassgeFantion:(UIControl *)controlmassge
{
    
    for (UIControl  *controlDATA in [bgView subviews])
    {
        for (UIImageView  *iamgeview in [controlDATA subviews])
        {
            if (iamgeview.tag ==20150505)
            {
                iamgeview.highlighted = NO;
            }
        }
       
    }
    
    for (UIImageView  *iamgeview in [controlmassge subviews])
    {
        if (iamgeview.tag ==20150505)
        {
            iamgeview.highlighted = YES;
        }
    }
    
    //选中某个字体
    if(controlmassge.tag == 0)
    {
       
        
        _FontSizeNuber = 13;
        
        
    }else if (controlmassge.tag == 1)
    {
        _FontSizeNuber = 16;
        
    }else if (controlmassge.tag == 2)
    {
        _FontSizeNuber = 19;

    
    }else if (controlmassge.tag == 3)
    {
        _FontSizeNuber = 22;
        
    }
}


@end
